﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class PhieuDichVu_DAO
    {
        private static PhieuDichVu_DAO m_instance = null;

        public static PhieuDichVu_DAO Instance
        {
            get
            {
                if (m_instance == null)
                    m_instance = new PhieuDichVu_DAO();
                return m_instance;
            }
        }


        /// <summary>
        /// Lấy mã phiếu dịch vụ lớn nhất
        /// </summary>
        /// <returns></returns>
        public DataTable LayMaPhieuDichVuMax()
        {
            try
            {
                SqlConnection cnn = SQLConnection.Instance.SqlConnection;
                SqlCommand cmd = new SqlCommand("GET_MAPHIEUDICHVU_MAX", cnn);
                cmd.CommandType = CommandType.StoredProcedure;

                //cmd.Parameters.Add("@makhachhang", SqlDbType.Char, 10);
                //cmd.Parameters["@makhachhang"].Value = id;

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable table = new DataTable();
                da.Fill(table);

                return table;
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// <summary>
        /// Thêm phiếu dịch vụ mới 
        /// </summary>
        /// <returns></returns>
        public bool ThemPhieuDichVuMoi(string ngaydk, string ngaygiao, string makh, long tongtien)
        {
            try
            {
                SqlConnection cnn = SQLConnection.Instance.SqlConnection;
                SqlCommand cmd = new SqlCommand("ADD_PHIEUDICHVU_MOI", cnn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@ngaydk", SqlDbType.SmallDateTime);
                cmd.Parameters["@ngaydk"].Value = ngaydk;
                cmd.Parameters.Add("@ngaygiao", SqlDbType.SmallDateTime);
                cmd.Parameters["@ngaygiao"].Value = ngaygiao;
                cmd.Parameters.Add("@makhachhang", SqlDbType.NVarChar, 10);
                cmd.Parameters["@makhachhang"].Value = makh;
                cmd.Parameters.Add("@tongtien", SqlDbType.Money);
                cmd.Parameters["@tongtien"].Value = tongtien;

                cmd.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
